import Mock from "mockjs"
import type { MockMethod } from 'vite-plugin-mock'

export default [
  //账号登录
  {
    url: '/api/user/login',
    method: 'post',
    response: ({query}) => {
      return Mock.mock({
        code: 0,
        msg: 'ok',
        data: {
          "userid | 1-100": 100,
          uname: '@cname',
          token: 'fewklfjewkfjeklfjewklfjlewfjewklfjelfjelfjew',
          avatar: "https://imgs.699pic.com/images/600/035/521.jpg!list1x.v2",
          // 路由权限
          routes: [
            '/wther',
            '/origin',
            '/harvest',
            '/people',
            '/record',
            '/harvest/look',
            '/harvest/add',
            '/harvest/addrecord',
            '/harvest/edit',
            '/harvest/goReap',
            '/harvest/statistics'
          ]
        }
      })
    }
  },
  // 用户列表
  {
    url: '/api/user/list',
    method: 'get',
    response: ({query}) => {
      const page=query.page? Number(query.page):1
      const size=query.size?Number(query.size):1
      // mockjs来生成假数据
      const people = Mock.mock({
        [`people|${size}`]:[    //生成4条数据
          {
            "id|+1": 1,
            name: "@cname",
            time: "@datetime",
            "player|1": ["主管", "农场主"],
            "top|1": ["无", "农场主"],
            "soil|1-3": ["@pick(['地块1', '地块2', '地块3'])"],
            "tel": /^1[3-9]\d{9}$/,
            "num|1": ["@pink['0','1']"],
           "job|1": ["@pick(['农场主', '植保负责人', '地块负责人','种植工人','采摘员','气象检测员'])"],
           "note|1-3":["@pick(['已完成','有错误','机器故障','人员未到位','网络故障','天气大雨'])"],
           "account":'梨花'
          }
        ]
      })
      return {
        code: 0,
        msg: 'ok',
        data: {
          ...people,
          total:100
        }
      }
    }
  },
  // 删除单个用户  使用id进行删除
  {
    url: '/api/user/:id',
    method: 'delete',
    response: () => {
      return {
        code: 0,
        msg: 'ok',
        // 1表示成功，非1为失败
        data: 1
      }
    }
  },
  // 接受新增用户
  {
    url: '/api/user/create',
    method: 'post',
    response: () => {
      //   const people = Mock.mock({
      //   ["people|4"]:[    //生成4条数据
      //     {
      //       "id|+1": 1,
      //       name: "@cname",
      //       time: "@datetime",
      //       "player|1": ["主管", "农场主"],
      //       "top|1": ["无", "农场主"],
      //       "soil|1-3": ["@pick(['地块1', '地块2', '地块3'])"],
      //       "tel": /^1[3-9]\d{9}$/,
      //       "num|1": ["@pink['0','1']"]
      //     }
      //   ]
      // })
      return {
        code: 0,
        msg: 'ok',
        // 新增返回的数据结果情况
        // 1.返回新增的用户在数据表中的id值
        // 2.返回新增用户的的记录数据，数据它是包含id值的
        data:10 
        // {
          // ...people
        
        // }
      }
    }
  },
  // 根据用户id返回对应的用户数据,此数据没有密码
  {
    url: '/api/user/:id',
    method: 'get',
    response: () => {
      return {
        code: 0,
        msg: 'ok',
        data: {
          id: 1,
          name: "@cname",
          time: "@datetime",
          player: "主管",
          top: "农场主",
          soil: "地块1",
          tel: /^1[3-9]\d{9}$/
        }
      }
    }
  },
  // 根据用户id来修改用户信息
  {
    url: '/api/user/:id',
    method: 'put',
    response: () => {
      return {
        code: 0,
        msg: 'ok',
        data: 1
      }
    }
  },
] as MockMethod[]